﻿Public Class CLabelCheckState2 : Inherits CStateBase

    ''' <summary>
    ''' 実行可能かを判断する
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function IsEnter(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CLabelCheckState.IsEnter")
        If CCommon.isInStr(task.ActionCd, "LABEL", "CHNG") Then
            Return True
        Else
            Return False
        End If
    End Function

    ''' <summary>
    ''' 実行メソッド
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExecute(ByVal task As CTaskBase) As CStateBase
        Dim nextState As CStateBase = Nothing
        Dim pdaTask As CPDATask2 = DirectCast(task, CPDATask2)
        Dim webMng As CWebManager = CWebManager.GetInstance
        Dim checkInfo As CCheck = CCheck.GetIns
        Dim AppManager As CApplicationManager = CApplicationManager.GetInstance

        'Dim waitTask As CPersonal = New CPersonal(pdaTask)
        Debug.WriteLine("CLabelCheckState.DoExecute...START")

        If task.ProcessText = "" Then
            '' リーダーからデータを取得する(待ち時間制限なし)
            pdaTask.WindowManager.SetMessage(CConst.CNS_MSG_021, CConst.COLOR_BLACK, CConst.COLOR_GREEN)
            task.ProcessText = task.ReadTextWait(-1)
            Debug.WriteLine("読んだバーコード:" & task.ProcessText)
        End If

        If Not CPersonal.CodeCheck(task.ProcessText, Me) Then
            task.ProcessText = ""
            Return Me
        End If

        '出荷取消場合
        ''バーコード判別(統括コード)
        Select Case CBarcode.GetBarcodeType(task.ProcessText)
            '従業員コード
            Case EnumBarcodeType.EMP_CODE
                Debug.WriteLine("社員番号読みました。")

                If Not AppManager.m_AppSetting.IsStaticReadEmpCd Then
                    '社員番号
                    '交代
                    'waitTask.Waiting(CCommon.CNS_MSG_064, pdaTask.WindowManager.GetWindowMode())
                    Dim EmpData As CCheck.EmpData = checkInfo.ChkEmpData(task.ProcessText)
                    pdaTask.WindowManager.SetEmpInfo(EmpData.empCd & ":[" & EmpData.empName & "]") '
                    pdaTask.EmpCd = EmpData.empCd

                    task.ActionCd = "CHNG"
                    task.ProcessText = ""

                    Return DoBaseExecute(task)
                Else
                    CPersonal.ErrorWindow2(pdaTask, EnumWindowMode.ALERT_MODE, _
                                                              Color.Black, CConst.EnumSound.ALERT_BUZZ, CConst.CNS_MSG_020, Color.White)
                    task.ActionCd = "LABEL"
                    task.ProcessText = ""
                    Return DoBaseExecute(task)
                End If

            Case EnumBarcodeType.SEND_CODE, EnumBarcodeType.KEY_SEND
                Debug.WriteLine("送信コード読みました。")
                Dim sendFlg As Boolean = CPersonal.ConfirmWindow2(pdaTask, EnumWindowMode.YESNO_MODE, _
                                            Color.Black, CConst.EnumSound.YESNO_BUZZ, CConst.CNS_MSG_026, Color.White)
                If sendFlg Then
                    Dim filePath As String = CApplicationManager.GetRealPath(CApplicationManager.SETTING_PATH, CApplicationManager.EnumSpecialFolder.PATH_MYDOCUMENT)
                    CBgControl.BgThread("CANCEL", "csv", filePath, checkInfo.GetCancelLabelDataList(pdaTask.PdaNo, pdaTask.EmpCd, "USE"), CConst.CANCEL_UPLOAD)
                    pdaTask.WindowManager.SetMessage(CConst.CNS_MSG_027, CConst.COLOR_BLACK, CConst.COLOR_GREEN)

                End If
                task.ActionCd = "LABEL"
                task.ProcessText = ""
                Return DoBaseExecute(task)

            Case EnumBarcodeType.INNER_LABEL_CODE
                'ユニークコード
                Dim uniqueCd As String = CBarcode.getBarcodeVl(task.ProcessText, CBarcode.GetBarcodeType(task.ProcessText), _
                                                                    EnumBarcodeType.UNIQUE_CD)
                Dim orderCd As String = checkInfo.GetLabelOrderCd(uniqueCd)

                '出荷取消コード
                task.ActionCd = "CANCEL_LABEL"
                nextState = GetNextState(task)
                Return nextState

            Case EnumBarcodeType.END_LABEL_CODE

                Debug.WriteLine("終了コード読みました。")
               
                ''ラベル読込終了
                pdaTask.WindowManager.SetMessage(CConst.CNS_MSG_023, CConst.COLOR_BLACK, CConst.COLOR_GREEN)
                'サーバー送信
                Dim filePath As String = CApplicationManager.GetRealPath(CApplicationManager.SETTING_PATH, CApplicationManager.EnumSpecialFolder.PATH_MYDOCUMENT)
                CBgControl.BgThread("CANCEL", "csv", filePath, checkInfo.GetCancelLabelDataList(pdaTask.PdaNo, pdaTask.EmpCd, "END"), CConst.CANCEL_UPLOAD)
                pdaTask.WindowManager.SetMessage(CConst.CNS_MSG_027, CConst.COLOR_BLACK, CConst.COLOR_GREEN)

                'uniqueCd.csv 書き出し
                Dim FPath As String = CApplicationManager.GetRealPath("action\", CApplicationManager.EnumSpecialFolder.PATH_MYDOCUMENT)
                CFiles.FileOutput("UniqueCd.csv", FPath, checkInfo.GetUniqueCdDataList)

                checkInfo.Release()
                pdaTask.WindowManager.BaseRelease()
                pdaTask.WindowManager.CloseWindow()


        End Select


        task.ProcessText = ""
        nextState = GetNextState(task)
        Return nextState
    End Function

    ''' <summary>
    ''' 終了メソッド(未使用)
    ''' </summary>
    ''' <param name="task"></param>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Overrides Function DoExit(ByVal task As CTaskBase) As Boolean
        Debug.WriteLine("CLabelCheckState.DoExit")
        Return True
    End Function


End Class
